package com.itheima.dbservice;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mapper.BlackListMapper;
import com.itheima.pojo.BlackList;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListServiceApiImpl implements BlackListServiceApi {
    @Autowired
    private BlackListMapper blackListMapper;
    //获取黑名单
    @Override
    public IPage<BlackList> getBlackListById(Long uid, Integer page, Integer pagesize) {
        //条件查询
        LambdaQueryWrapper<BlackList> wrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<BlackList> eq = wrapper.eq(BlackList::getUserId, uid);
        //开始分页
        Page<BlackList> ipage = new Page<>(page,pagesize);
        //查询结果并返回
        Page<BlackList> blackListPage = blackListMapper.selectPage(ipage, eq);
        //返回结果
        return blackListPage;
    }

    @Override
    public void removeBlackList(Long blackUserId) {
        //1.构造条件查询
        LambdaQueryWrapper<BlackList> wrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<BlackList> eq = wrapper.eq(BlackList::getBlackUserId, blackUserId);
        //2.执行删除
        blackListMapper.delete(eq);
    }
}
